package com.xyz.springcloud.controller;

import com.xyz.springcloud.entity.CommonResult;
import com.xyz.springcloud.entity.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @author 肖咉卓
 */
@RestController
public class PaymentController {
    @Value("${server.port}")
    private String serverPort;

    /**
     * 模拟数据库
     */
    public static HashMap<Long, Payment> hashMap = new HashMap<>();
    static {
        hashMap.put(1L,new Payment(1L,"6sfd5sfd54sfd4sd4sfd55s4fd45sfd4"));
        hashMap.put(2L,new Payment(2L,"dfg7dg8d8g4d84gd5fg4d5g4df5dg4dg"));
        hashMap.put(3L,new Payment(3L,"y6u5i6y5i6yu2i3y2iy1ui1y1iyi21yi"));
    }

    @GetMapping(value = "/paymentSQL/{id}")
    public CommonResult<Payment> paymentSQL(@PathVariable("id") Long id){
        Payment payment = hashMap.get(id);
        CommonResult<Payment> result = new CommonResult<>(200,"form msql,serverPort:"+serverPort,payment);
        return result;
    }

}
